package com.bi.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 图表组件实体类
 * 
 * @author BI Platform Team
 * @since 1.0.0
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("tb_chart_component")
public class ChartComponent implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 组件名称
     */
    private String name;

    /**
     * 组件显示名称
     */
    private String displayName;

    /**
     * 组件描述
     */
    private String description;

    /**
     * 图表类型
     */
    private ChartType chartType;

    /**
     * 数据源类型
     */
    private DataSourceType dataSourceType;

    /**
     * 数据源配置
     */
    private String dataSourceConfig;

    /**
     * 宽表ID(如果数据源是宽表)
     */
    private Long wideTableId;

    /**
     * 数据组件ID(如果基于数据组件)
     */
    private Long dataComponentId;

    /**
     * SQL查询语句
     */
    private String sqlQuery;

    /**
     * ES查询配置
     */
    private String esQuery;

    /**
     * 图表配置JSON
     */
    private String chartConfig;

    /**
     * 数据配置JSON（维度、指标等）
     */
    private String dataConfig;

    /**
     * 样式配置JSON
     */
    private String styleConfig;

    /**
     * 交互配置JSON
     */
    private String interactionConfig;

    /**
     * 缓存配置
     */
    private String cacheConfig;

    /**
     * 刷新周期(分钟)
     */
    private Integer refreshInterval;

    /**
     * 预览图片URL
     */
    private String previewUrl;

    /**
     * 状态
     */
    private ComponentStatus status;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新人
     */
    private String updater;

    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 版本号
     */
    @Version
    private Integer version;

    /**
     * 图表类型枚举
     */
    public enum ChartType {
        LINE("折线图"),
        BAR("柱状图"),
        PIE("饼图"),
        SCATTER("散点图"),
        AREA("面积图"),
        GAUGE("仪表盘"),
        RADAR("雷达图"),
        FUNNEL("漏斗图"),
        TREEMAP("矩形树图"),
        SUNBURST("旭日图"),
        HEATMAP("热力图"),
        CANDLESTICK("K线图"),
        BOXPLOT("箱线图"),
        PARALLEL("平行坐标"),
        SANKEY("桑基图"),
        GRAPH("关系图"),
        WORDCLOUD("词云图"),
        LIQUIDFILL("水球图"),
        CUSTOM("自定义图表");

        private final String description;

        ChartType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 数据源类型枚举
     */
    public enum DataSourceType {
        WIDE_TABLE("数据宽表"),
        DATA_COMPONENT("数据组件"),
        DATABASE("数据库"),
        ELASTICSEARCH("Elasticsearch"),
        API("REST API"),
        FILE("文件数据源");

        private final String description;

        DataSourceType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 组件状态枚举
     */
    public enum ComponentStatus {
        DRAFT("草稿"),
        ACTIVE("启用"),
        INACTIVE("停用"),
        DELETED("已删除");

        private final String description;

        ComponentStatus(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }
}